<?php
namespace App\Admin\Service;
use app\admin\model\ShopAccessAuth;
use app\Result;
class AccessService
{
    public function appAccess($app_id)
    {
        $auths = ShopAccessAuth::where('app_id', $app_id)->column('access_id');
        return Result::Success($auths);
    }

    public function setAppAccess($data)
    {
        try {
            $access_id = $data['access_id'];
            $app_id = $data['app_id'];
            $data = [];
            foreach ($access_id as $v) {
                $data[] = ['access_id' => $v, 'app_id' => $app_id];
            }
            ShopAccessAuth::where('app_id', $app_id)->delete();
            ShopAccessAuth::insertAll($data);
            return Result::Success();
        } catch (\Exception $e) {
            return Result::Error($e->getMessage());
        }
    }
}